marketingModule.controller("MarketingMallCtrl", ["$scope", "$timeout", "$state", "permissionProvider", "systemConfigSvc", "$q", "$stateParams", "$log", "loginContext", "enums", "mallSvc", "sessionCache", "procurementSvc", "officeOptionSvc", "commonSvc", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v, y) {
    "use strict";
    var p = "",
        w = l.getCache(l.keys.EtradePlatformSendCouponState),
        b = function() {
            r.loadPermissions().then(function(t) {
                if (t = _.filter(t, function(n) {
                        return n == "stockCenter.stockViewAgreementPrice" || n == "stockCenter.stockOrderRequestNoLimit" || n == "stockCenter.stockSubmitOrderRequest" || n == "stockCenter.stockApproveOrderRequest" || n == "procurement.procurementOperateShoppingCart" || n == "procurement.procurementViewShoppingCart"
                    }), t.length > 0) {
                    var i = _.find(t, function(n) {
                        return n == "procurement.procurementOperateShoppingCart"
                    });
                    i && t.push("stockCenter.stockOperateShoppingCart");
                    i = _.find(t, function(n) {
                        return n == "procurement.procurementViewShoppingCart"
                    });
                    i && t.push("stockCenter.stockViewShoppingCart")
                }
                n.permissionCodes = t;
                u.getMallHostUrl().then(function(t) {
                    if (t) {
                        var i = Date.parse(new Date);
                        switch (n.action) {
                            case h.ProcurementMallAction.AddCart:
                                p = t + "/cart.js?v=" + i;
                                break;
                            case h.ProcurementMallAction.Pay:
                                p = t + "/pay.js?v=" + i;
                                break;
                            case h.ProcurementMallAction.OrderDetail:
                                p = t + "/orderDetail.js?v=" + i;
                                break;
                            case h.ProcurementMallAction.ServiceOrder:
                                p = t + "/service.js?v=" + i;
                                break;
                            default:
                                p = t + "/plugin.js?v=" + i
                        }
                        Ares.Loader.loadJs(p, function() {
                            n.goToMall(t)
                        })
                    }
                })
            })
        },
        nt = function() {
            var t = w.loadObject(),
                n = f.defer();
            return t == !0 ? n.resolve() : c.sendCoupons().success(function(t) {
                t.success && w.saveObject(!0);
                n.resolve(t)
            }).error(function() {
                n.resolve()
            }), n.promise
        },
        k = function() {
            var t = f.defer();
            return a.isNeedcheckPayorder().then(function(i) {
                n.isNeedCheckPayorder = i.data;
                t.resolve(!0)
            }), t.promise
        },
        d = function() {
            var t = f.defer();
            return v.getOfficeOption(v.optionKeys.IsNeedCheckAgreePrice).then(function(i) {
                n.isNeedCheckAgreePrice = i;
                t.resolve(!0)
            }), t.promise
        },
        g = function() {
            var t = f.defer();
            return y.getBmsToken().then(function(i) {
                n.universalAccessToken = i;
                t.resolve(!0)
            }), t.promise
        };
    (function() {
        n.action = e.action;
        n.tradeNo = e.tradeNo;
        n.params = i.params;
        f.all([k(), d(), g()]).then(function() {
            b()
        })
    })()
}]);
marketingModule.controller("MarketingScrmCtrl", ["$scope", "$stateParams", "$timeout", "systemConfigSvc", "$q", "$log", function(n, t) {
    "use strict";
    (function() {
        n.action = t.action
    })()
}]);
marketingModule.controller("TenantCenterCtrl", ["$scope", "$timeout", "$state", "permissionProvider", "systemConfigSvc", "$q", "$stateParams", "$log", "loginContext", "enums", "mallSvc", "sessionCache", function() {
    "use strict";
    (function() {})()
}]);
marketingModule.directive("marketingMallView", ["$log", "$timeout", "loginContext", "dataDicSvc", "enums", function(n, t, i, r, u) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        controller: "MarketingMallCtrl",
        templateUrl: "/app/marketing/views/marketing-mall-view.html",
        link: function(n, t) {
            var e = function(t) {
                    t && (n.tradeNo ? new MallPc({
                        msgOrigin: t,
                        containerId: "mall_pc",
                        baseUrl: t,
                        token: n.universalAccessToken,
                        permissionCodes: n.permissionCodes,
                        userId: i.userId,
                        tenantId: i.tenantId,
                        officeId: i.officeId,
                        isTenantAdmin: i.isTenantAdmin,
                        tradeNo: n.tradeNo,
                        receiptType: 1,
                        isNeedCheckPayorder: n.isNeedCheckPayorder,
                        isNeedCheckAgreePrice: n.isNeedCheckAgreePrice
                    }) : n.serviceSn ? new MallPc({
                        msgOrigin: t,
                        containerId: "mall_pc",
                        baseUrl: t,
                        token: n.universalAccessToken,
                        permissionCodes: n.permissionCodes,
                        userId: i.userId,
                        tenantId: i.tenantId,
                        officeId: i.officeId,
                        isTenantAdmin: i.isTenantAdmin,
                        serviceSn: n.serviceSn,
                        isNeedCheckPayorder: n.isNeedCheckPayorder,
                        isNeedCheckAgreePrice: n.isNeedCheckAgreePrice
                    }) : n.settlementOrderNo ? new MallPc({
                        msgOrigin: t,
                        containerId: "mall_pc",
                        baseUrl: t,
                        token: n.universalAccessToken,
                        permissionCodes: n.permissionCodes,
                        userId: i.userId,
                        tenantId: i.tenantId,
                        officeId: i.officeId,
                        isTenantAdmin: i.isTenantAdmin,
                        settlementOrderNo: n.settlementOrderNo,
                        receiptType: 2,
                        isNeedCheckPayorder: n.isNeedCheckPayorder,
                        isNeedCheckAgreePrice: n.isNeedCheckAgreePrice
                    }) : r.officeDic.load().then(function(r) {
                        var o = _.find(r, function(n) {
                                return n.id === i.officeId
                            }),
                            e, f;
                        n.fullscreen = !0;
                        e = r.length > 1 && !i.isAdminOffice && (i.isRoot || i.offices.length > 1);
                        f = {
                            msgOrigin: t,
                            containerId: "mall_pc",
                            baseUrl: t,
                            token: n.universalAccessToken,
                            permissionCodes: n.permissionCodes,
                            userId: i.userId,
                            tenantId: i.tenantId,
                            officeId: i.officeId,
                            isTenantAdmin: i.isTenantAdmin,
                            orderSn: n.params.orderSn,
                            lcCode: n.params.lcCode,
                            isNeedCheckPayorder: n.isNeedCheckPayorder,
                            isNeedCheckAgreePrice: n.isNeedCheckAgreePrice,
                            loginName: i.userName,
                            officeName: o.name,
                            canSwitchOffice: e
                        };
                        n.action === u.ProcurementMallAction.Invoice && (f.url = "invoice/list");
                        new MallPc(f)
                    }))
                },
                f = function() {
                    var n = document.getElementById("mall_pc"),
                        t = n.receiveMsgHandler;
                    t && (window.removeEventListener("message", t, !1), console.log("removeReceiveMsgHandler"), n.receiveMsgHandler = null)
                };
            (function() {
                n.goToMall = e;
                t.on("$destroy", function() {
                    f()
                });
                n.$on("$destroy", function() {
                    f()
                })
            })()
        }
    }
}]);
marketingModule.directive("marketingPttView", ["$log", "$timeout", "loginContext", "systemConfigSvc", "$rootScope", "appNav", "officeOptionSvc", "aresDialog", "systemOptionSvc", function(n, t, i, r, u, f, e, o, s) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        controller: "MarketingPttCtrl",
        templateUrl: "/app/marketing/views/marketing-ptt-view.html",
        link: function(n, o) {
            var c = function() {
                    (_.isObject(u.PreviewTriage) && _.isEmpty(u.PreviewTriage) || !_.isObject(u.PreviewTriage)) && r.getPttSiteConfig().then(function(n) {
                        if (n) {
                            var r = n.apiRootUrl,
                                f = n.pluginRootUrl,
                                o = f + "?v=" + Date.parse(new Date);
                            s.getSystemTempOption(s.optionKeys.IsTempPrecheckTriage).then(function(n) {
                                var f = n;
                                e.getOfficeOption(e.optionKeys.IsPrecheckTriageEnabled).then(function(n) {
                                    var s = n,
                                        e = 2;
                                    s ? e = 1 : f && (e = 0);
                                    Ares.Loader.loadJs(o, function() {
                                        t(function() {
                                            var n = {
                                                containerId: "preview_triage",
                                                enabledState: e,
                                                baseUrl: r,
                                                token: "bearer " + i.apiToken,
                                                goToBuyPreCheckTriage: l
                                            };
                                            u.PreviewTriage = new PreviewTriage(n)
                                        })
                                    })
                                })
                            })
                        }
                    })
                },
                h = function() {
                    var n = document.getElementById("preview_triage"),
                        t = n.receiveMsgHandler;
                    t && (window.removeEventListener("message", t, !1), console.log("removeReceiveMsgHandler"), n.receiveMsgHandler = null)
                },
                l = function() {
                    f.goToEnterpriseApplications()
                };
            (function() {
                c();
                o.on("$destroy", function() {
                    h();
                    u.PreviewTriage = null
                });
                n.$on("$destroy", function() {
                    h()
                })
            })()
        }
    }
}]);
marketingModule.controller("MarketingPttCtrl", ["$scope", "$stateParams", "$timeout", "systemConfigSvc", "$q", "$log", function(n, t) {
    "use strict";
    (function() {
        n.action = t.action
    })()
}]);
marketingModule.directive("marketingScrmView", ["$log", "$timeout", "loginContext", "systemConfigSvc", "$rootScope", "appNav", "permissionProvider", "aresDialog", function(n, t, i, r, u, f, e, o) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        controller: "MarketingScrmCtrl",
        templateUrl: "/app/marketing/views/marketing-scrm-view.html",
        link: function(n, s) {
            var c = function() {
                    (_.isObject(u.ScrmPc) && _.isEmpty(u.ScrmPc) || !_.isObject(u.ScrmPc)) && r.getScrmSiteConfig().then(function(r) {
                        if (r) {
                            var f = r.webRootUrl,
                                e = r.apiRootUrl,
                                o = f + "/plugin.js?v=" + Date.parse(new Date);
                            Ares.Loader.loadJs(o, function() {
                                t(function() {
                                    var t = {
                                        msgOrigin: f,
                                        apiServer: e,
                                        containerId: "scrm_pc",
                                        env: "kouqiang",
                                        baseUrl: f + "/portal/",
                                        token: "bearer " + i.apiToken,
                                        startChat: function(n) {
                                            u.$broadcast("start-chat", n)
                                        },
                                        openPage: function(n, t) {
                                            l(n, t)
                                        }
                                    };
                                    n.action && (t.path = n.action);
                                    u.ScrmPc = new ScrmPc(t, 1500)
                                })
                            })
                        }
                    })
                },
                l = function(n, t) {
                    switch (n) {
                        case "referral":
                            a(t)
                    }
                },
                a = function() {
                    if (e.isAllowed(permissionCode)) {
                        var n = i.isGroup ? "referralCenter.arrivalReferralConfig" : "referralCenter.dashboard";
                        f.goToState(n)
                    } else o.warn("提示", "您没有推荐管理页面权限")
                },
                h = function() {
                    var n = document.getElementById("scrm_pc"),
                        t = n.receiveMsgHandler;
                    t && (window.removeEventListener("message", t, !1), console.log("removeReceiveMsgHandler"), n.receiveMsgHandler = null)
                };
            (function() {
                c();
                s.on("$destroy", function() {
                    h();
                    u.ScrmPc = null
                });
                n.$on("$destroy", function() {
                    h()
                })
            })()
        }
    }
}]);
marketingModule.directive("openPlatformCenterView", ["$log", "$timeout", "loginContext", "systemConfigSvc", function(n, t, i, r) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/marketing/views/open-platform-center-view.html",
        link: function(n, t) {
            var u = function() {
                    n.action === "mli" ? f() : e()
                },
                f = function() {
                    r.getMliSiteConfig().then(function(n) {
                        if (n) {
                            var t = Date.parse(new Date),
                                i = n.webRootUrl + "/plugin.js?v=" + t;
                            Ares.Loader.loadJs(i, function() {
                                new Medicare({
                                    apiServer: n.webRootUrl,
                                    containerId: "mli_pc",
                                    token: n.token,
                                    accountId: n.accountId
                                })
                            })
                        }
                    })
                },
                e = function() {
                    r.getOpenPlatformUrl().then(function(n) {
                        if (n) {
                            n = n.replace("/#/tokenLogin?", "/?v=" + window.openPlatformTimestamp + "#/tokenLogin?");
                            var i = document.createElement("iframe");
                            i.src = n;
                            t.find("#mli_pc")[0].appendChild(i)
                        }
                    })
                },
                i = function() {
                    var n = document.getElementById("mli_pc"),
                        t = n.receiveMsgHandler;
                    t && (window.removeEventListener("message", t, !1), console.log("removeReceiveMsgHandler"), n.receiveMsgHandler = null)
                };
            (function() {
                u();
                t.on("$destroy", function() {
                    i()
                });
                n.$on("$destroy", function() {
                    i()
                })
            })()
        }
    }
}]);
marketingModule.directive("tenantCenterView", ["$log", "$timeout", "$window", "$q", "loginContext", "systemConfigSvc", "$rootScope", "commonSvc", function(n, t, i, r, u, f, e, o) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        controller: "TenantCenterCtrl",
        templateUrl: "/app/marketing/views/tenant-center-view.html",
        link: function(n) {
            var s = function(n, i) {
                if (_.isObject(e.TenantPc) && _.isEmpty(e.TenantPc) || !_.isObject(e.TenantPc)) {
                    var r = n.webRootUrl + "/plugin.js";
                    Ares.Loader.loadJs(r, function() {
                        t(function() {
                            e.TenantPc = new BMSPc({
                                api_server: n.apiRootUrl,
                                containerId: "tenant_pc",
                                officeId: u.officeId,
                                tenantId: u.tenantId,
                                saas_token: "bearer " + u.apiToken,
                                token: i
                            }, 1500)
                        })
                    })
                }
            };
            (function() {
                n.height = i.innerHeight - 180 + "px";
                r.all([f.getBmsSiteConfig(), o.getBmsToken()]).then(function(n) {
                    s(n[0], n[1])
                })
            })()
        }
    }
}]);